package complete测试;

import lombok.SneakyThrows;

import java.util.concurrent.*;

/**
 * @author: yangwk37982
 * @date: 2022/8/1 14:31
 */
public class CompleteTest {
    static Executor executor = Executors.newFixedThreadPool(3);
    static CompletionService<String> service = new ExecutorCompletionService<>(executor);

    public static void test1(int i) throws InterruptedException, ExecutionException {


        Future<String> submit = service.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return "HelloWorld--" + i;
            }
        });
    }

    public static void main(String[] args) {

        new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                int i = 100000000;
                while (i-- > 0) {
                    test1(i);
                }
            }
        }).start();
    }
}
